package com.oauth2.demo2.tokenstore;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @ClassName TokenStoreCon
 * @Description 自定义配置token存储，及tjwt生成token
 * @Author Liujt
 * @Date 2020/1/16 17:24
 **/
@Configuration
public class TokenStoreConfig {

    /**
     * 使用JWT定义token
     */
    @Configuration
    public static class JwtTokenConfig {
        @Bean
        public TokenStore jwtTokenStore() {
            return new JwtTokenStore(jwtAccessTokenConverter());
        }

        @Bean
        public JwtAccessTokenConverter jwtAccessTokenConverter() {
            JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
            accessTokenConverter.setSigningKey("SigningKey");//token签名
            return accessTokenConverter;
        }
    }

}
